import axios from 'axios'
export default {
  namespaced: true,
  state: {
    // num: localStorage.getItem('cartNum') || 100,
    num: 100,
    cates: []
  },
  mutations: {
    ADD_NUM (state, n) {
      state.num += n
      // localStorage.setItem('cartNum', state.num)
    },
    REDUCE_NUM (state, n) {
      state.num -= n
    },
    INIT_CATES (state, cates) {
      state.cates = cates
    }
  },
  getters: {
    DOUBLE_NUM (state) {
      return state.num * 2
    }
  },
  actions: {
    FETCH_CATES (context, params) {
      axios.get('https://api.it120.cc/conner/shop/goods/category/all', {
        params
      }).then(res => {
        if (res.data.code === 0) {
          context.commit('INIT_CATES', res.data.data)
        }
      })
    }
  }
}
